package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbUserJob;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbUserJobDao extends JpaRepository<TbUserJob, Integer> {

	TbUserJob getByUserIdAndJobId(Integer userId, Integer jobId);

	@Query("select uj.id from TbUserJob uj where uj.userId=:userId")
	List<Integer> findAllIdByUserId(@Param("userId") Integer userId);

	@Query("select uj.id from TbUserJob uj where uj.jobId=:jobId")
	List<Integer> findAllIdByJobId(@Param("jobId") Integer jobId);

	@Query("select uj.id from TbUserJob uj where uj.userId=:userId and uj.id not in(:idList)")
	List<Integer> findAllIdByUserIdAndIdNotIn(@Param("userId") Integer userId, @Param("idList") List<Integer> idList);

	@Modifying
	@Query("delete from TbUserJob uj where uj.id in(:idList)")
	void deleteByIdIn(@Param("idList") List<Integer> idList);

	@Query("select uj.jobId from TbUserJob uj where uj.userId=:userId")
	List<Integer> findJobIdByUserId(@Param("userId") Integer userId);
}
